package com.windy.spring.rest;

import java.security.Principal;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.windy.spring.data.AccessInfo;

@Controller
public class AccessController {
	
	
	/*@RequestMapping(value = "/login", method = RequestMethod.GET)
	@ResponseBody
	public AccessInfo logIn() {
		AccessInfo accessInfo=new AccessInfo();
		accessInfo.setLoggedIn(false);
		accessInfo.setDescription("This is the login page");
		return accessInfo;
	}
	
	@RequestMapping(value = "/logout", method = RequestMethod.GET)
	@ResponseBody
	public AccessInfo logOut() {
		AccessInfo accessInfo=new AccessInfo();
		accessInfo.setLoggedIn(false);
		accessInfo.setDescription("This is the logout page");
		return accessInfo;
	}*/
	
	@RequestMapping(value="/login", method = RequestMethod.GET)
	public String login(ModelMap model) {
 
		return "login";
 
	}
	
	@RequestMapping(value="/logout", method = RequestMethod.GET)
	public String logout(ModelMap model) {
 
		return "login";
 
	}
	
	@RequestMapping(value = "/welcome", method = RequestMethod.GET)
	@ResponseBody
	public AccessInfo welcome(Principal principal) {
		AccessInfo accessInfo=new AccessInfo();
		accessInfo.setUserId(principal.getName());
		accessInfo.setLoggedIn(true);
		accessInfo.setDescription("This is the welcome page");
		return accessInfo;
	}

	@RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
	@ResponseBody
	public AccessInfo loginFailed() {
		AccessInfo accessInfo=new AccessInfo();
		accessInfo.setLoggedIn(false);
		accessInfo.setDescription("This is the loginfailed page");
		return accessInfo;
	}

}
